function formatNumber (n) {
  const str = n.toString()
  return str[1] ? str : `0${str}`
}

export function formatTime (date) {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  const t1 = [year, month, day].map(formatNumber).join('/')
  const t2 = [hour, minute, second].map(formatNumber).join(':')

  return `${t1} ${t2}`
}

export default {
  formatNumber,
  formatTime,
  showError,
  showException
}
function showError () {
  wx.showModal({
    title: '加载失败',
    content: '网络太卡了！！！',
    confirmText: '重试',
    success (res) {
      if (res.confirm) {
        wx.startPullDownRefresh()
      }
    }
  })
}
function showException (message) {
  wx.showModal({
    title: '加载失败',
    content: message || '网络请求返回异常！',
    confirmText: '重试',
    success (res) {
      if (res.confirm) {
        wx.startPullDownRefresh()
      }
    }
  })
}
